from pkg_resources import iter_entry_points, load_entry_point

import logging
log = logging.getLogger(__name__)

def load_ep_from_group(group, ep_name):
    '''Loads an entry point given a (setuptools) group.
    
    '''
    pkgs_searched = []
    ep_name = ep_name or ''
    
    for ep in iter_entry_points(group):
        pkgs_searched.append(' '.join( (ep.dist.project_name, ep.dist.version) ))
        if ep.name == ep_name:
            log.debug('found %s in dist: %s' % (ep_name,ep.dist) )
            try:
                cls = load_entry_point(ep.dist, group, ep.name)
            except ImportError:
                log.error('failed to load %s entry point for group: %s' % (ep_name, group) )
                raise ImportError
            return cls
    
    log.debug('Could not find %s entry point for group: %s', (ep_name, group) )
    log.debug('Searched packages: %s' % list(set(pkgs_searched)) )
    raise ImportError
        


def logout():
    # get the session
    
    # delete the user object
    
    # save the session
    pass
